package com.shujia.day03;

public class Demo12ArrayOperator {
    public static void main(String[] args) {
        /*
            TODO 数组常见操作:
                1.数组遍历
         */

//       TODO 1.数组遍历
        int numArr[] = {1, 2, 3, 3, 2, 1, 4, 5, 6};

        // numArr.length 表示数组的长度
        for (int i = 0; i < numArr.length; i++) {
            // 遍历所有的下标,根据下标进行取数据
            System.out.println("获取到数据:" + numArr[i]);
        }
        System.out.println("+++++++++++分割+++++++++++");
        int index = 0;
        while (index < numArr.length) {
            System.out.println("获取到数据:" + numArr[index]);
            index++;
        }
        System.out.println("+++++++++++分割+++++++++++");
        // TODO 注意: 增强for遍历数据
        // 每次循环都直接取出 数组中的元素
        for (int elem : numArr) {
            System.out.println("获取到数据:" + elem);
        }


        /*
           TODO  数组获取最值(获取数组中的最大值最小值)
         */
        int max = numArr[0];
        int min = numArr[0];
        for (int elem : numArr) {
            max = elem > max ? elem : max;
            min = elem < min ? elem : min;
        }
        System.out.println("max:"+max);
        System.out.println("min:"+min);

        /*
           TODO 数组元素逆序 (就是把元素对调)
         */

        for (int i = 0; i < numArr.length / 2; i++) {
//            int startNum = numArr[i];
//            int tmpNum = startNum;
//            int endNum = numArr[numArr.length - i - 1];
//            numArr[i] = endNum;
//            numArr[numArr.length - i - 1] = tmpNum;

            int tmpNum = numArr[i];
            numArr[i] = numArr[numArr.length - i - 1];
            numArr[numArr.length - i - 1] = tmpNum;
        }
        System.out.println("====================分割====================");
        for (int elem : numArr) {
            System.out.println("获取到数据:" + elem);
        }



    }
}
